package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Order;
import com.itheima.vo.OrderSuccessfulVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @author jshstart
 * @creat 2020-11-15 13:06
 */
public interface OrderMapper extends BaseMapper<Order> {
    @Select("select tm.name member,ts.name setmeal,date_format(o.order_date,'%Y-%m-%d') order_date, o.order_no from t_order o\n" +
            "join t_member tm on tm.id=o.member_id\n" +
            "join t_setmeal ts on ts.id=o.setmeal_id\n" +
            "where o.id=#{id}")
    OrderSuccessfulVo findOrderInfo(Long id);
    @Select("  select s.name ,count(*) value\n" +
            "  from t_order o\n" +
            "  join t_setmeal s on s.id=o.setmeal_id\n" +
            "  group by setmeal_id")
    List<Map> selectSetmealPercent();


    @Update("update t_order set pay_status=1 where order_no=#{tradeNo} ")
    void updateByOrderNo(String tradeNo);

    @Select("select pay_status from t_order where order_no=#{orderNo} ")
    Integer selStatus(String orderNo);

    @Select("select count(*) from t_order o\n" +
            "left join rpt_date rd  on rd.fdate = o.order_date\n" +
            "where rd.fdate= #{formatDate}")
    int findTodayOrderNumber(@Param("formatDate") String formatDate);

    @Select("select count(*) from t_order o\n" +
            "left join rpt_date rd  on rd.fdate = o.order_date\n" +
            "where rd.fdate= #{formatDate} and isflash=1")
    int findTodayVisitsNumber(String formatDate);

    @Select("select count(*) from t_order o\n" +
            "left join  rpt_date  rd on rd.fdate= o.order_date\n" +
            "where  rd.fweek=#{thisweek}")
    int findThisWeekOrderNumber(@Param("thisweek") int thisweek);

    @Select("select count(*) from t_order o\n" +
            "left join  rpt_date  rd on rd.fdate= o.order_date\n" +
            "where  rd.fweek=#{thisweek} and isflash=1")
    int findThisWeekVisitsNumber(int thisweek);

    @Select("select count(*) from t_order o\n" +
            "left join  rpt_date  rd on rd.fdate= o.order_date\n" +
            "where  rd.fmonth=#{thismonth}")
    int findThisMonthOrderNumber(@Param("thismonth") String thismonth);

    @Select("select count(*) from t_order o\n" +
            "left join  rpt_date  rd on rd.fdate= o.order_date\n" +
            "where  rd.fmonth= #{thismonth}  and isflash=1")
    int findThisMonthVisitsNumber(String thismonth);

}
